package xml;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import constants.XMLConstants;

import data.DataStorage;
import data.Game;
import data.Player;

public class DataToXML {
	public static void getXMLFromData(DataStorage data){
		
	}
	
	public static Element createGameElement(Document doc, Game game){
		Element gameElement = doc.createElement(XMLConstants.GAME);
		gameElement.setAttribute(XMLConstants.ENVIRONMENT, game.getEnvironment().toString());
		gameElement.appendChild(createPlayer(doc, game.getPlayer1()));
		gameElement.appendChild(createPlayer(doc, game.getPlayer2()));
		
		return gameElement;
	}
	public static Element createPlayer(Document doc, Player player){
		Element playerElement = doc.createElement(XMLConstants.PLAYER);
		playerElement.setAttribute(XMLConstants.NAME, player.getPlayerName());
		playerElement.setAttribute(XMLConstants.ID, String.valueOf(player.getPlayerID()));
		return playerElement;
	}
}
